package com.shopping_back.mapper;

import com.shopping_back.pojo.entity.Spu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 * 商品SPU表 Mapper 接口
 * </p>
 *
 * @author Jack
 * @since 2025-07-12
 */
@Mapper
public interface SpuMapper extends BaseMapper<Spu> {
    // 查询SPU及其关联的SKU列表（仅查询已上架的SPU）
    @Select("SELECT s.*, sku.* FROM spu s " +
            "LEFT JOIN sku ON s.id = sku.spu_id " +
            "WHERE s.id = #{spuId} AND s.status = true") // 注意这里使用s.status（SPU表的状态）
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "skuList", column = "id", many = @Many(select = "com.shopping_back.mapper.SkuMapper.selectBySpuId"))
    })
    Spu getSpuWithSkuList(Long spuId);
}
